<?php

/**
 * patriarch actions.
 *
 * @package    jiazhang
 * @subpackage patriarch
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class patriarchActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
        $page = $request->getParameter('page',1);
        $dql = Doctrine::getTable('PatriarchArticle')->createQuery()->orderBy('created_at desc');
        $this->pager = new sfDoctrinePager('PatriarchArticle',30);
        $this->pager->setQuery($dql);
        $this->pager->setPage($page);
        $this->pager->init();
  }
  
   public function executeChange_display(sfWebRequest $request)
  {
       
    $this->forward404Unless($theme = Doctrine::getTable('PatriarchArticle')->findOneById($id = (int)$request->getParameter('id')));
    $display = (int)$request->getParameter('display',0);
    $theme->setDisplay($display)->save();
    $this->getUser()->setFlash('success', '话题显示状态更改！');
    
    $this->redirect($request->getReferer());
  }
  
   public function executeChange_comment_display(sfWebRequest $request)
  {
       
    $this->forward404Unless($theme = Doctrine::getTable('PatriarchComment')->findOneById($id = (int)$request->getParameter('id')));
    $display = (int)$request->getParameter('display',0);
    $theme->setDisplay($display)->save();
    $this->getUser()->setFlash('success', '话题显示状态更改！');
    
    $this->redirect($request->getReferer());
  }
  
  public function executeComments(sfWebRequest $request){
        $page = $request->getParameter('page',1);
        $id = (int)$request->getParameter('id');
        $this->theme = Doctrine::getTable('PatriarchArticle')->findOneById($id);
        $this->pager = Doctrine::getTable('PatriarchComment')->createQuery()->where('p_id = ?',$id)->orderBy('created_at desc')->execute();
//        $this->pager = new sfDoctrinePager('PatriarchComment',30);
//        $this->pager->setQuery($dql);
//        $this->pager->setPage($page);
//        $this->pager->init();
  }
  
}
